package com.kgc.scd.producer;

import com.kgc.scd.contant.SeckillConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;
import java.util.Map;

/**
 * Created On : 2022/6/8.
 * <p>
 * Author     : 98730
 * <p>
 * Description: 消息生产者-队列模式
 */
@Slf4j
@Component
public class AccountPayResultProducer {

    @Autowired(required = false)
    private JmsMessagingTemplate jmsMessagingTemplate;

    public void payOrderResultNotify(String mQName, Map<String,String> resultMap){
        log.info("~~~~~~ 支付成功，发送结果通知到目标响应队列：{}，支付结果：{} ~~~~~~", mQName,resultMap);

        // 创建目标消息队列对象
        Destination destination = new ActiveMQQueue(mQName);

        // 发送消息
        jmsMessagingTemplate.convertAndSend(destination,resultMap);
    }

    @JmsListener(destination = SeckillConstant.SECKILL_SECKILL_RESP_QUEUE_NAME)
    public void returnPayOrderResultNotify(String returnMsg) {
        log.info(returnMsg);
    }
}
